<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div>
    <progress id="progressBar" value="0" max="100"></progress>
    <a href="#" id="downloadLink">Download</a>
</div>
<script>
    document.getElementById('downloadLink').addEventListener('click', function(e) {
        e.preventDefault();
        var xhr = new XMLHttpRequest();
        xhr.open('POST', '/file/download', true);
        xhr.responseType = 'blob'; // 如果你打算下载文件
        var formData = new FormData();
        formData.append("objectName","file/20240511/img/f3926dfe9f304dc39d27ffa70449c0d9.ico");
        xhr.onprogress = function(e) {
            if (e.lengthComputable) {
                var percentComplete = (e.loaded / e.total) * 100;
                var progressBar = document.getElementById('progressBar');
                progressBar.value = percentComplete;
            }
        };

        xhr.onload = function() {
            if (this.status === 200) {
                // 创建blob对象URL
                var blob = new Blob([this.response], {type: 'application/octet-stream'});
                var url = window.URL.createObjectURL(blob);

                // 创建一个a标签用于下载
                var a = document.createElement('a');
                a.href = url;
                a.download = 'file/20240511/img/f3926dfe9f304dc39d27ffa70449c0d9.ico'; // 设置下载文件名
                document.body.appendChild(a);
                a.click();

                // 清理
                window.URL.revokeObjectURL(url);
                document.body.removeChild(a);
            }
        };

        xhr.send(formData);
    });
</script>
</body>
</html>